#ifndef MY_BOSSMODE_H
#define MY_BOSSMODE_H



#include "Main.h"
#include "InputName.h"



class BossMode : public Main
{
public:
	BossMode( CScene** ppScene )
	{
		m_ppScene			= ppScene;
		m_pLevelParam		= NULL;
		m_dwScore			= 0;
		m_dwHurryTick		= 0;
		m_dwLevelTimeTick	= 0;
		m_dwLevelTimeLeft	= 0;
		m_bLogicStart		= true;
		m_dwCurAboutString	= UN_DEFINE;

		CSquare::m_pMainScene = this;
		CMonster::m_pMainScene = this;

		m_nCurHP		= 0;
		m_nMaxHeart		= DEFAULT_HEART + 2;
		m_dwMoney		= 100;
		m_Hammer.InitHammer( HAMMER_BRONZE, true );
		m_dwLevel		= 10;

	}

	void InitScene()
	{
		Main::InitScene();

		m_pNextScene = new LevelInfo( m_ppScene, this, m_dwLevel );
		m_pNextScene->InitScene();
		m_pNextScene->SetAnimate( ANIME_FADE_OUT, ANIME_CMD_START_LOGIC );

	}

	inline
	void	ReduceHP( int nReduction )
	{
		if( nReduction < 0 &&
			( m_dwLevelTimeLeft <  ( 0 - nReduction ) ) )
			m_dwLevelTimeLeft = 0;
		else
			m_dwLevelTimeLeft += ( nReduction << 8 );

	}

	void RenderTime()
	{
		RECT rc = m_mapSprObj[MAIN_TIME_FRONT].GetScriptRect();
		RECT rcStr = { 440, rc.top - 40, 480, rc.top };
		WCHAR wszMin[8];
		wsprintf( wszMin, L"x%d", (int)( m_dwLevelTimeLeft / 60000) );
		g_CDDraw.SetFontAlign( false );
		g_CDDraw.SetFontSize( 35, FW_HEAVY );
		g_CDDraw.DDrawText( wszMin, &rcStr );
		g_CDDraw.SetFontAlign();
		g_CDDraw.SetFontSize();
		rc.right = ( rc.right - rc.left ) * ( (float)( m_dwLevelTimeLeft % 60000) / 60000.0f );
		rc.bottom -= rc.top;
		rc.left = 0;
		rc.top = 0;

		m_mapSprObj[MAIN_TIME_BACK].RenderScript();
		m_mapSprObj[MAIN_TIME_FRONT].RenderScript( &rc );

	}

	inline	void	HurryUp()	{}

	void RunGameWin()
	{
		if( m_dwCurAboutString != MAIN_CONGRATULATIONS )
		{
			g_CResource.StopMusic();
			g_CResource.PlaySound( SOUND_WIN );
			m_dwCurAboutString = MAIN_CONGRATULATIONS;

			if( !g_CGame.CheckPassword( 2 ) )
			{
				g_CGame.GetSetting()->dwPassword2 = g_CGame.CalPassword( 2 );
				g_CGame.SaveSetting();

			}

		}

		if( !ShowAboutString( m_dwCurAboutString ) )
		{
			InitAboutString( m_dwCurAboutString );

			if( m_dwLevelTimeLeft < g_CGame.LoadBossTime( false ) )
			{
				*m_ppScene = new InputName( m_ppScene );
				(*m_ppScene)->InitScene();
				((InputName*)(*m_ppScene))->SetRecordType( RECORD_TYPE_TIME, m_dwLevelTimeLeft );

			}
			else
			{
				*m_ppScene = new Menu( m_ppScene, true );
				((Menu*)*m_ppScene)->AddImgOption( MENU_BTN_BACK_TO_TITLE, MENU_BTN_TYPE_IMG_BTN );
				((Menu*)*m_ppScene)->AddImgOption( MENU_BTN_EXIT_GAME, MENU_BTN_TYPE_IMG_BTN );
				(*m_ppScene)->InitScene();

			}

		}

	}

protected:
	inline
	void CalTime()
	{
		m_dwLevelTimeLeft += g_CWhacAMouseApp.GetTickCount() - m_dwLevelTimeTick;
		m_dwLevelTimeTick = g_CWhacAMouseApp.GetTickCount();

	}

	inline	bool	CheckIsGameOver()	{ return false; }
	inline	bool	CheckIsWin()		{ return ( m_Square[BOSS_SQUARE].GetSquareState() == BOTTON ) ? true : false; }

	void SetLevel( DWORD dwLevel )
	{
		m_dwLevel = dwLevel;
		m_CurLeverParam = g_LevelParam[m_dwLevel-1];
		m_pLevelParam = &m_CurLeverParam;

		for( int index = 0; index != 9; ++index )
			m_Square[index].m_fMoveSpeed = m_pLevelParam->fSquareSpeed;

		m_dwLevelTimeLeft = 0;

		if( m_pLevelParam->dwBoss )
		{
			m_Square[BOSS_SQUARE].SetupMonster( m_pLevelParam->dwBoss );
			m_Square[BOSS_SQUARE].m_pMonster->m_nCurHP *= 1;
			m_Square[BOSS_SQUARE].m_pMonster->SetMaxHP( m_Square[BOSS_SQUARE].m_pMonster->m_nCurHP );
			m_Square[BOSS_SQUARE].SetSquareState( UPING );

		}

	}

	LEVEL_PARAM		m_CurLeverParam;

};



#endif